<template>
  <div style="padding-bottom: 44px">
    <div class="center-match-banner"></div>
    <div style="background-color: #fff">
      <ul class="link-tab">
        <li v-for="link, index in links" :key="index" :class="index == active ? 'active' : ''" @click="goLink(index)">
          {{ link.name }}
        </li>
      </ul>
    </div>
    <div>
      <div id="link1"></div>
      <div class="match-title">
        <img src="/static/images/forum_avgnda.png">
      </div>
      <div class="match-card" style="background-image: none;">
        {{ luntanyichenginfo.content }}
      </div>

    </div>
    <div id="link2"></div>
    <div class="match-title">
      <img src="/static/images/forum_rese.png">
    </div>
    <ul class="news-card-list">
      <li class="news-card" v-for="card, index in luntanyichenglist" :key="index">
        <elImage :src="card.logoimage"
                 fit="cover" class="news-card-img"></elImage>
        <div class="news-title">
          {{ card.title }}
        </div>
        <div class="action-rese">
          <button class="go-rese">立即预约</button>
        </div>
      </li>
    </ul>
    <div style="text-align: center">
      <Pagination background layout="prev, pager, next" :page-size='6' :total="total" @current-change="currentChange">
      </Pagination>
    </div>
  </div>

</template>
<script>
import {goAnchor} from '@/util'
import {Image, Pagination} from "element-ui"
import {luntanyicheng, luntanyvyue} from "../../api/cms.js";

export default {
  components: {
    elImage: Image,
    Pagination
  },
  data() {
    return {
      active: 0,
      links: [
        {path: '/match_center', name: '论坛议程'},
        {path: '/match_center', name: '论坛预约'}
      ],
      events: null,
      luntanyichenginfo: {},
      luntanyichenglist: [],
      total: 0,
    }
  },
  mounted() {
    this.events = window.addEventListener('scroll', this.handle)
  },
  created() {
    this.getluntanyicheng(1);
    this.getluntanyvyue();
  },
  methods: {
    getluntanyicheng() {
      luntanyicheng().then(res => {
        this.luntanyichenginfo = res.data.data;
      })
          .catch(res => {
            console.log(res);
          });
    },
    getluntanyvyue(page) {
      luntanyvyue({
        page,
        limit: 6
      }).then(res => {
        this.luntanyichenglist = res.data.data.rows;
        this.total = res.data.data.total
      }).catch(res => {
        console.log(res);
      });
    },
    currentChange(index) {
      this.getluntanyvyue(index)
    },
    handle() {
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      var link1 = document.querySelector('#link1').offsetTop
      var link2 = document.querySelector('#link2').offsetTop
      var list = [{index: 0, numer: Math.abs(scrollTop - link1 + 84)}, {
        index: 1,
        numer: Math.abs(scrollTop - link2 + 84)
      }]
      list.sort((a, b) => a.numer - b.numer)
      this.active = list[0].index
    },
    goLink(index) {
      this.active = index
      goAnchor(`#link${index + 1}`)
    }
  },
  beforeDestroy() {
    window.removeEventListener("scroll", this.handle)
    this.events = null
  }
}
</script>
<style scoped>
.center-match-banner {
  width: 100%;
  background-image: url(/static/images/forum_banner.png);
  background-repeat: no-repeat;
  height: 472px;
  background-size: cover;
  min-width: 1440px;
}

.match-title {
  width: 1240px;
  margin: 84px auto 0;
  padding-left: 24px;
  padding-top: 10px;
  background: url(/static/images/match_line.png) no-repeat;
  background-position: right bottom;
  height: 124px;
}

.match-card {
  margin: 40px auto 0;
  border-radius: 25px;
  background-color: rgb(255, 255, 255);
  box-shadow: 0px 5px 25px 0px rgba(0, 0, 0, 0.2);
  width: 1240px;
  min-height: 550px;
  background-image: url(/static/images/match_card.png);
  background-size: 100% auto;
  background-position: right center;
  padding: 55px 50px;
  font-size: 16px;
  color: #000000;
  line-height: 30px;
}

.match-margin-bg {
  background-color: rgb(1, 67, 160);
  width: 100%;
  height: 304px;
  margin: 109px 0 74px;
}

.center-match-bg {
  background: url(/static/images/match_bg.png) no-repeat;
  background-position: center 12%;
  background-size: 100% auto;
}

.news-card {
  border-radius: 20px;
  background-color: rgb(255, 255, 255);
  box-shadow: 2.5px 4.33px 7px 0px rgb(0, 0, 0, 0.2);
  width: 392px;
  padding-bottom: 18px;
  overflow: hidden;
  position: relative;
  display: inline-block;
  margin-bottom: 30px;
}

.news-card-img {
  width: 100%;
  height: 238px;
}

.news-title {
  font-size: 18px;
  color: #2b2e2e;
  overflow: hidden;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  padding: 20px 34px 0;
  line-height: 30px;
  margin-top: -4px;
}

.news-card-list {
  width: 1228px;
  margin: 50px auto 0;
}

.news-tag-list {
  padding: 0 34px;
}

.news-tag {
  font-size: 13px;
  color: #3d80ff;
  height: 26px;
  padding: 0 14px;
  background: #ebf5ff;
  display: inline-block;
  line-height: 26px;
  margin-right: 12px;
}

.news-times {
  position: absolute;
  bottom: 20px;
  left: 0px;
  padding: 0 34px;
  display: flex;
  width: 100%;
  font-size: 12px;
  color: #828282;
}

.news-card:nth-child(3n-1) {
  margin-left: 26px;
  margin-right: 26px;
}

.news-times span {
  flex: 1;
}

.go-rese {
  appearance: none;
  border-width: 1px;
  border-color: rgb(1, 67, 160);
  border-style: solid;
  width: 92px;
  height: 31px;
  background: transparent;
  border-radius: 5px;
  color: rgb(1, 67, 160);
}

.action-rese {
  text-align: right;
  padding-right: 30px;
}
</style>
